package org.example.backend.demos.web.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * Description: 通用的返回结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;
    private String msg;
    private T data;


    // 带数据的返回成功的结果
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.msg = "成功" ;
        result.data = data;
        result.code = 200;
        return result;
    }

    // 返回错误的结果
    public static <T> Result error(T data) {
        Result<T> result = new Result<>();
        result.msg = "失败";
        result.data =data;
        result.code = 401;
        return result;
    }
}
